<?php
/**
 * Created by IntelliJ IDEA.
 * User: dhy
 * Date: 2015/9/11
 * Time: 15:54
 */

namespace App\Http\Middleware\Customer;
use App\Http\Models\Admin\Sys\SysParam;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
class SeoMiddleware {
    public function handle($request,  $next){

        $ASSETS = $request['ASSETS'];
        if( $ASSETS == null){
            $ASSETS = array();
        }

        //添加当前路由下需要添加的js和css, 配置项在config/asstes.php. 注意路由转换, 如admin.userinfo 那么在config里面为admin_userinfo
        $routeName = Route::currentRouteName();

        $seos = SysParam::where('type',Config::get('common.system_type_seo'))->get();
        $seo = array();
        if($seos){
            foreach($seos as $item){
                $seo[$item->name] = $item->value;
            }
        }
        $async = SysParam::where('name',Config::get('common.system_async_config'))->first();


        $ASSETS['SEO'] =  array(
            'title'=>$seo['site_seo_title'],
            'description'=>$seo['site_seo_description'],
            'keywords'=>$seo['site_seo_keywords'],
//            'other_meta'=>$seo['site_seo_other_meta'],

            'async'=>$async? $async->value:"",


        );

        $request['ASSETS'] = $ASSETS;

        return $next($request);
    }


}